package org.example.mutithread.future;

import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.ListenableFuture;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;

public class App {

    private static final Logger LOGGER = LoggerFactory.getLogger(App.class);

    public static void main(String[] args) {
        Callable<String> c1 = () -> {
            //step 1
            LOGGER.info("执行step 1");
            TimeUnit.SECONDS.sleep(3);
            return "step1 result";
        };

        Callable<String> c2 = () -> {
            //step 2
            LOGGER.info("执行step 2");
            TimeUnit.SECONDS.sleep(10);
            if (true) {
                throw new RuntimeException("==============");
            }
            return "step2 result";
        };


        FutureUtil.getInstance(c1, c2).submit(new ITaskRs() {
            @Override
            public <T> void onSuccess(T result) {
                LOGGER.info("result:{}", result);
            }

            @Override
            public void onFailure(Throwable t) {
                LOGGER.error("error:{}", t);
            }
        }, c1, c2);

        LOGGER.info("--------------end.");
    }
}
